package com.gtt.lazy.controller;

import java.util.List;

import com.gtt.lazy.domain.Agent;
import com.gtt.lazy.service.AgentService;

/**
 * 代理商管理Action
 * 
 * @author 高甜甜
 * @date 2009-7-9
 */
public class AgentAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private AgentService agentService;

	private List<Agent> results;
	private Agent agent;

	private int id;
	private String name;
	private String desc;
	private String address;
	private String phone;
	private int level;

	public String list() {
		// 确定所要显示的页数
		if (page == 0)
			page = 1;
		int start = (page - 1) * Constant.SIZE;
		results = agentService.list(start, Constant.SIZE);
		setPagination(agentService.count(), Constant.SIZE, page);
		return SUCCESS;
	}

	public String toAdd() {
		return SUCCESS;
	}

	public String add() {
		Agent agent = new Agent(name, desc, address, phone, level);
		agentService.add(agent);
		return SUCCESS;
	}

	public String toMod() {
		agent = agentService.get(id);
		return SUCCESS;
	}

	public String mod() {
		Agent agent = new Agent(name, desc, address, phone, level);
		agent.setId(id);
		agentService.update(agent);
		return SUCCESS;
	}

	public String del() {
		agentService.delete(id);
		return SUCCESS;
	}

	public List<Agent> getResults() {
		return results;
	}

	public void setResults(List<Agent> results) {
		this.results = results;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public Agent getAgent() {
		return agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public AgentService getAgentService() {
		return agentService;
	}

	public void setAgentService(AgentService agentService) {
		this.agentService = agentService;
	}

}
